package com.company.regist.servlet;

import com.company.regist.dao.FriendsDAOImpl;
import com.company.regist.dao.IFriendsDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/deletecheck")
public class DeleteCheckServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// HttpServletRequest req 
		// Tomcat自动创建的对象，会把用户的请求信息放入
		
//		HttpServletResponse resp
		// Tomcat自动创建的对象, 通过它给用户发信息
		
		// 1. 获取用户提交的参数
		String id = req.getParameter("id");

		int intId=Integer.parseInt(id);


		IFriendsDAO dao = new FriendsDAOImpl();
		int p=-1;
		try {
			p = dao.deleteById(intId);
			if(p>=1)
			{
				resp.setHeader("Content-Type","text/html;charset=utf-8");
				resp.getWriter().print("删除成功，即将为您跳转主页......");
				resp.setHeader("refresh","1,url=dirct.html");
			}
			else
			{
				resp.getWriter().print("delete fail");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		
	}
	

}
